<?php

/**
 * Helper function to theme user pictures
 */
function _theme_heartbeat_user_picture($user) {
  if (is_numeric($user)) {
    $user = user_load($user);
  }
  return '<span class="avatar">' . l(theme('imagecache', 'tiny_picture', $user->picture), 'user/' . $user->uid, array('html' => TRUE)) . '</span>';
}

/**
 * Theme helper function for comment button
 */
function _theme_heartbeat_comment_button($node = NULL, $link_text = '') {

  if ($link_text != '') {
    $link_title = $link_text;
    $class = 'heartbeat-comment-button';
  }
  else {
    $link_title = $node->comment_count > 0 ? $node->comment_count : '+';
    $class = 'heartbeat-comment-count';
  }

  $arguments = array(
    'attributes' => array(
      'onclick' => 'javascript:Drupal.heartbeat.toggleComments(this); return false;',
    )
  );

  return '<span class="' . $class . '">' . l($link_title, $_GET['q'], $arguments) . '</span>';
}

/**
 * Theme helper function for comment button
 */
function _theme_heartbeat_action_buttons($node, $message, $args = array()) {
  if (empty($args)) {
    $args = array(
      'comment' => $node->comment ? TRUE : FALSE,
      'wrap' => TRUE,
    );
  }
  $links = array();
  if (isset($args['wrap'])) {
    $links[] = '<div class="heartbeat-action-buttons">';
  }
  $links[] = '<span class="heartbeat_times">' . _theme_time_ago($message->timestamp) . '</span>';

  if (isset($args['comment']) && $args['comment']) {
    $links[] = _theme_heartbeat_comment_button($node, t('comment'));
  }
  if (isset($args['wrap'])) {
    $links[] = '</div>';
  }

  return implode('', $links);
}

/**
 * Helper function to theme the icon left
 */
function _theme_heartbeat_icon_left($type, $message, $node = NULL) {

  $output = '';

  $output .= '<div class="icon-left-margin">';
  $output .= '<span class="icon-left ' . $type. '-icon">';
  $output .= theme('imagecache', 'tiny_picture', $type . '.png');
  $output .= '</span>';
  $output .= '</div>';

  return $output;
}

/**
 * Theme helper function for comment button
 */
function _theme_heartbeat_teaser($node) {

  $output = '';

  $output .= '<h3>' . l($node->title, 'node/' . $node->nid) . '</h3>';

  $output .= '<div class="heartbeat-teaser">' . $node->teaser;
  $output .= ' ' . l(t('more'), 'node/'. $node->nid) . '</div>';

  return $output;
}

